﻿using Microsoft.ServiceBus.Messaging;
using System;

namespace Sustainalytics.Replication.Publisher
{
    public static class ReplicationUtils
    {
        public enum EntityType
        {
            None,
            News,
            Event,
            MostRecentActivity,
            AuthCredentials,
            Filter,
            FilterCriteria,
            UserFilterSettings,
            MostActiveReport,
            Portfolio,            
            PortfolioDetails,
            PortfolioUserInput,
            SubscribeToPortfolio,
            Insight,
            Notification,
        }

        public enum Operation
        {
            None,
            Create,
            Insert,
            Update,
            UpdateStatus,
            UpdateBatch,
            Delete,
            DeleteBatch,
            DeleteWhereByPortfolioId,
            DeleteWhereBySecurityIdAndPortfolioId,
            DeleteWhereIsAutomaticAndIsReadonly,
            DeleteAll,
            CreateOrUpdate,
            SavePasswordByUserId,
            SavePasswordByUsername,
            AddFilterCriteria,
            UpdateFilterCriteria,
            DeleteFilterCriteria,
            DeleteFilterCriteriaByIdTemplateIdAndFilterId,
            DeleteFilterCriteriaByFilterGroupId,
            DeleteResultOutput,
            DeleteAllFilterCriteriaByFilterId,
            UpdateSelectedCriteriaOrderNumber,
            SaveMostRecentActivity,
            RecordReportActivity,
            CreateOrUpdateBatch,
        }

        public enum ConnectionStringType
        {            
            ClientPlatform,
            ClientDW,
        }

        public static EntityType MessageEntityType(BrokeredMessage message)
        {
            EntityType messageEntityType = EntityType.None;
            if (message != null && message.Properties != null && message.Properties.ContainsKey("EntityType"))
                messageEntityType = (EntityType)Enum.Parse(typeof(EntityType), message.Properties["EntityType"].ToString());
            return messageEntityType;
        }

        public static Operation MessageOperation(BrokeredMessage message)
        {
            Operation messageOperation = Operation.None;
            if (message != null && message.Properties != null && message.Properties.ContainsKey("Operation"))
                messageOperation = (Operation)Enum.Parse(typeof(Operation), message.Properties["Operation"].ToString());
            return messageOperation;
        }

        public static ConnectionStringType MessageConnectionStringType(BrokeredMessage message)
        {
            ConnectionStringType connnectionStringType = ConnectionStringType.ClientPlatform;
            if (message != null && message.Properties != null && message.Properties.ContainsKey("ConnectionStringType"))
                connnectionStringType = (ConnectionStringType)Enum.Parse(typeof(ConnectionStringType), message.Properties["ConnectionStringType"].ToString());
            return connnectionStringType;
        }
    }
}
